package com.cda.mall.controller;


import com.cda.mall.dao.ProductCommentsMapper;
import com.cda.mall.service.IProductCommentsService;
import com.cda.mall.service.IProductService;
import com.cda.mall.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 * 商品 商品信息相关表：分类表，商品图片表，商品规格表，商品参数表 前端控制器
 * </p>
 *
 * @author cda
 * @since 2021-11-13
 */
@RestController
@RequestMapping("/product")
@CrossOrigin
@Api(value = "提供商品详细信息的接口",tags = "商品管理")
public class ProductController {

    @Autowired
    private IProductService productService;

    @Autowired
    private IProductCommentsService productCommentsService;

    @GetMapping("/detail-info/{pid}")
    @ApiOperation("商品基本信息查询接口")
    public ResultVO getProductBasicInfo(@PathVariable("pid") String pid){
        return productService.getProductBasicInfo(pid);
    }

    @GetMapping("/detail-params/{pid}")
    @ApiOperation("商品参数信息查询接口")
    public ResultVO getProductParams(@PathVariable("pid") String pid){
        return productService.getProductParamsById(pid);
    }

    @GetMapping("/detail-comments/{pid}")
    @ApiOperation("商品评论信息查询接口")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int",name = "pageNum",value = "当前页码",required = true),
            @ApiImplicitParam(dataType = "int",name = "limit",value = "每页显示条数",required = true)
    })
    public ResultVO getProductComments(@PathVariable("pid") String pid,int pageNum,int limit){
        return productCommentsService.listCommentsByProductId(pid,pageNum,limit);
    }

    @GetMapping("/detail-commentscount/{pid}")
    @ApiOperation("商品评价统计查询接口")
    public ResultVO getProductCommentsCount(@PathVariable("pid") String pid){
        return productCommentsService.getCommentCountByProductId(pid);
    }

}

